package com.example.easybuy.service.impl;

import com.example.easybuy.entity.News;
import com.example.easybuy.mappers.NewsMapper;
import com.example.easybuy.service.NewsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsMapper newsMapper;

@Override
    public PageInfo<News> newsByPage(Map<String, Object> map) {
        map.put("orderBy","createTime desc");
        PageHelper.startPage(map);
        List<News> list = newsMapper.newsByPage(map);
        return new PageInfo<>(list);
    }

    @Override
    public boolean delNews(int id) {
        return newsMapper.delNews(id) > 0;
    }

    @Override
    public boolean addNews(Map<String, Object> news) {
        return newsMapper.addNews(news) > 0;
    }

    @Override
    public boolean updateNews(Map<String,Object> news) {
        return newsMapper.updateNews(news) > 0;
    }

    @Override
    public News getNews(int id) {
        return newsMapper.getNews(id);
    }
}
